package sample.RTTI;

import java.lang.reflect.Constructor;
import java.lang.reflect.Method;

public class ShowMethods {

	static final String usage = "usage:\n" + "ShowMethods qualified.class.name\n"
			+ "To show all methods in class or :\n"
			+ "showMethods qualitified.class.name.word\n"
			+ "to search for methods involving word\n";

	public static void main(String[] args) {
		if (args.length < 1) {
			System.out.println(usage);
			System.exit(0);
		}

		Class c = null;
		try {
			c = Class.forName(args[0]);
		} catch (ClassNotFoundException e) {
			e.printStackTrace();
		}
		Method[] m = c.getMethods();
		Constructor[] ctor = c.getConstructors();
		if (args.length == 1) {
			for (int i = 0; i < m.length; i++) {
				System.out.println(m[i].toString());
			}
			for (int i = 0; i < ctor.length; i++) {
				System.out.println(ctor[i]);
			}

		} else {
			for (int i = 0; i < m.length; i++) {
				if (m[i].toString().indexOf(args[1]) != -1) {
					System.out.println(m[i].toString());
				}
			}
			for (int i = 0; i < ctor.length; i++) {
				if (ctor[i].toString().indexOf(args[i]) != -1) {
					System.out.println(ctor[i].toString());
				}
			}
		}
	}
}
